/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.modeldocument.primitives;

import java.io.Serializable;

public class Variant implements Serializable {
    

    public static enum Type {
        LONG,
        STRING,
        BOOLEAN,
        SHORT,
        FLOAT,
        DOUBLE;
    }
    
    
    public Variant(Type type, Object value) {
        m_type = type;
        m_value = value;
    }
    
    public Type getType() {
        return m_type;
    }
    
    public Long getLong() {
        return (Long)m_value;
    }
    
    public String getString() {
        return (String)m_value;
    }
    
    public boolean getBoolean() {
        return (Boolean)m_value;
    }
    
    public Short getShort() {
        return (Short)m_value;
    }
    
    public Float getFLoat() {
        return (Float)m_value;
    }
    
    public Double getDouble() {
        return (Double)m_value;
    }

    public String toString() {
        switch (m_type) {
        case LONG: return String.valueOf((Long)m_value);
        case STRING: return (String)m_value;
        case BOOLEAN:
            if ( (Boolean)m_value ) {
                return "true";
            } else {
                return "false";
            }
        case SHORT: return String.valueOf((Short)m_value);
        case FLOAT: return String.valueOf((Float)m_value);
        case DOUBLE: return String.valueOf((Double)m_value);
        default: return "";
        }
    }
    
    // -------------- Serilization -------
    
    /**
     * First serilization version
     */
    private static final long serialVersionUID = 1L;
    private Type m_type;
    private Object m_value; 

}
